#include "url/url.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;

int32 init(string filename, string url_s[], int32 size)
{
        if(filename.empty())  return -1;
        std::ifstream infile(filename.c_str());
        int32 pos = 0;
        while(!infile.fail())
        {
                char file_tmp[256];
                infile.getline(file_tmp, sizeof(file_tmp));
                url_s[pos] = string(file_tmp);
                cout << pos << "th url:" << url_s[pos] << endl;
                if(++pos >= size) break;
        }
        infile.close();
        return pos;

}
int main(int argc, char* argv[])
{
	if(argc != 2) return -1;
	string url_s[20000];
	//int32 num = init(argv[1], url_s, 20000);
	////////////////////////////////////////
	std::ifstream infile(argv[1]);
	int32 num = 0;
	while(!infile.fail())
	{
		char file_tmp[1000];
		infile.getline(file_tmp, sizeof(file_tmp));
		url_s[num] = string(file_tmp);
		//cout << num << "th url:" << url_s[num] << endl;
		if(++num >= 20000) break;
	}
	infile.close();
	////////////////////////////////////////
	URL u;
	uint64 success_num = 0, failure_num = 0;
	for(int32 pos = 0; pos < num - 1; ++pos)
	{
		u.set_url(url_s[pos]);
		if(u.parse_url())
		{
			++success_num;
			//u.test_output();
		}
		else
		{
			++failure_num;
			cout << "此URL解析失败:" << u.url << endl;
		}
	}
	cout << "结果如下:" << endl << 
		"成功:" << success_num << endl << 
		"失败:" << failure_num << endl;
	return 0;
}
